export default class BoomFlame {
    radius:number=0;
    elapse:number=0;
    active:boolean;
    constructor(public id, public life, public center,public  angle,public  length,public  create_time,public  paint) {
        this.id = id;
        this.create_time = create_time;
        this.life = life;
        this.center = center;
        this.angle = angle;
        this.length = length;

        this.radius = 15;
        this.elapse = 0;

        this.paint = paint;

        this.active = true;
    }

    set_properties(id, life, center, angle, length, create_time, paint) {
        this.id = id;
        this.create_time = create_time;
        this.life = life;
        this.center = center;
        this.angle = angle;
        this.length = length;

        this.radius = 15;
        this.elapse = 0;

        this.paint = paint;

        this.active = true;
    }

    update_boom_flame = function (draw) {
        if (this.life - this.elapse <= 0) {
            this.remove_boom_flame();
            return;
        }
        this.paint.getComponent(cc.Graphics).clear();
        let ratio_elapse_life = this.elapse / this.life;
        let angle = this.angle;
        let center = this.center;
        let len = this.length;
        let r = this.radius

        center = [Math.trunc(center[0] + len * ratio_elapse_life * Math.cos(angle)), Math.trunc(center[1] + len * ratio_elapse_life * Math.sin(angle))];
        let start_point = [Math.trunc(center[0] - r * (1 - ratio_elapse_life) * Math.cos(angle)), Math.trunc(center[1] - r * (1 - ratio_elapse_life) * Math.sin(angle))];
        let end_point = [Math.trunc(center[0] + r * (1 - ratio_elapse_life) * Math.cos(angle)), Math.trunc(center[1] + r * (1 - ratio_elapse_life) * Math.sin(angle))];
        let control_point_1 = [Math.trunc(center[0] + r * (1 - ratio_elapse_life) * Math.cos(angle + 0.5 * Math.PI) * 0.38), Math.trunc(center[1] + r * (1 - ratio_elapse_life) * Math.sin(angle + 0.5 * Math.PI) * 0.38)];
        let control_point_2 = [Math.trunc(center[0] + r * (1 - ratio_elapse_life) * Math.cos(angle - 0.5 * Math.PI) * 0.38), Math.trunc(center[1] + r * (1 - ratio_elapse_life) * Math.sin(angle - 0.5 * Math.PI) * 0.38)];

        // cc.log('draw');
        // cc.log(this.paint);
        draw(this.paint.getComponent(cc.Graphics), start_point, end_point, control_point_1, control_point_2);



    }

    remove_boom_flame  () {
        this.paint.getComponent(cc.Graphics).clear();
        this.paint.destroy();
        // cc.log('remove');
        this.active = true;
        this.id = null;
        this.create_time = null;
        this.life = null;
        this.center = null;
        this.angle = null;
        this.length = null;

        this.radius = null;
        this.elapse = null;

        this.paint = null;


    }
}